<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/2/8
 * Time: 18:13
 */

/**
 * 用来写入 pid的函数
 * 六星教育 @shineyork老师
 * @param  [type] $data [description]
 * @param  [type] $path [description]
 * @return [type]       [description]
 */
function pidPut($data, $path){
    (empty($data)) ? file_put_contents($path, null) : file_put_contents($path, $data.'|', 8) ;
}
/**
 * 获取pid的函数
 * 六星教育 @shineyork老师
 * @param  [type] $path [description]
 * @return [type]       [description]
 */
function pidGet($path){
    $string = file_get_contents($path);
    return explode("|",  substr($string, 0 , strlen($string) - 1));
}



function dd($message, $desc = null)
{
    echo "=====>>> ".$desc." start\n";

    if (is_array($message)) {
        echo var_export($message, true);
    } else if (is_string($message)) {
        echo $message."\n";
    } else {
        var_dump($message);
    }

    echo "=====>>> ".$desc." end\n";
}

function debug($data, $flag = false)
{
    if ($flag) {
        echo "<pre>";
        var_dump($data);
        echo "</pre>";
    } else {
        echo '============>>'.$data.PHP_EOL;
    }
}

function send($conn, $data, $flag = true)
{
    if ($flag) {
        fwrite($conn, $data);
    } else {
        $response = "HTTP/1.1 200 OK\r\n";
        $response .= "Content-Type: text/html;charset=UTF-8\r\n";
        $response .= "Connection: keep-alive\r\n";
        $response .= "Content-length: ".strlen($data)."\r\n\r\n";
        $response .= $data;

        fwrite($conn, $response);
    }
}